import 'package:flutter/material.dart';

class TimeLineItem extends StatelessWidget {
  final bool isPrimary;
  final bool isLatest;
  final bool disabled;
  final Widget child;

  const TimeLineItem({
    Key key,
    @required this.child,
    this.isPrimary = false,
    this.isLatest = false,
    this.disabled = false,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 10),
      child: Stack(
        children: [
          line(),
          Positioned(
            left: isPrimary ? 6 : 8,
            top: 0,
            child: dot(context),
          ),
        ],
      ),
    );
  }

  Widget line() {
    return Container(
      decoration: BoxDecoration(
        border: Border(
          left: BorderSide(
            color: isLatest ? Colors.transparent : Colors.black26,
            width: 2,
          ),
        ),
      ),
      margin: EdgeInsets.symmetric(horizontal: 15),
      padding: EdgeInsets.fromLTRB(10, 0, 0, 30),
      child: Padding(
        padding: EdgeInsets.only(left: 5),
        child: child,
      ),
    );
  }

  Widget dot(BuildContext context) {
    if (isPrimary) {
      return Container(
        decoration: BoxDecoration(
          shape: BoxShape.circle,
          border: Border.all(
            width: 3,
            color: Theme.of(context).backgroundColor,
          ),
        ),
        child: Container(
          height: 13,
          width: 13,
          decoration: BoxDecoration(
            color: Colors.white,
            shape: BoxShape.circle,
            border: Border.all(
              width: 3,
              color: Theme.of(context).primaryColor,
            ),
          ),
        ),
      );
    }

    return Container(
      padding: EdgeInsets.all(3),
      decoration: BoxDecoration(
        shape: BoxShape.circle,
        color: Theme.of(context).backgroundColor,
      ),
      child: Container(
        height: 10,
        width: 10,
        decoration: BoxDecoration(
          shape: BoxShape.circle,
          color: disabled ? Colors.black26 : Theme.of(context).primaryColor,
        ),
      ),
    );
  }
}
